package com.kk.util.test.thread;

import org.bouncycastle.jcajce.provider.symmetric.TLSKDF;

/**
 * @author: kevin
 * @data: 2018-09-07 09:55
 * @desc:
 */
public class Thread2 implements Runnable {

    private String name;

    public Thread2(String name) {
        this.name = name;
    }

    @Override
    public void run() {
//        System.out.println("运行" + this.name);
        if (this.name.equals("A")) {
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        if (this.name.equals("B")) {
            notifyAll();
            System.out.println("B唤醒A线程");
        }
        for (int i = 0; i < 5; i++) {
            System.out.println("运行"+this.name+": "+i);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new Thread2("A"));
        Thread t2 = new Thread(new Thread2("B"));
        t1.start();
        t2.start();

        //与继承Thread一样
//        Thread t1 = new Thread(new Thread2("C"));
//        Thread t2 = t1;
//        t1.start();
//        t2.start();
    }

}
